package com.eaoa.uc.pubmessage.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.constants.PubMessageConstants;
import com.eaoa.query.pub.PubMessageQuery;
import com.eaoa.uc.pubmessage.form.MessageSearchCondition;
import com.eaoa.uc.pubmessage.form.MessageSearchForm;

public class MessageReceiveSearchAction extends EABaseAction {

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		MessageSearchForm sform = (MessageSearchForm) form;
		sform.initConditionPost();
		MessageSearchCondition condition = (MessageSearchCondition) sform
				.getCondition();

		PubMessageQuery query = new PubMessageQuery();
		query.setReceiver(getEmployee(request).getAccountno());
		query.setSendername(condition.getSendername());
		query.setSubject(condition.getSubject());
		
		query.setSenderdate(condition.getSenderdatefrom(), condition.getSenderdateto());
		
		query.setStatus(condition.getStatus());
		query.setStatus(PubMessageConstants.MESSAGE_STATUSES_RECEIVE);
		query.setIslock("N");
		query.setMessagetype(condition.getMessagetype());
		query.setPageRange(sform.getPageinfo());
		query.execute();

		request.setAttribute("results", query.getResults());

		return mapping.findForward("success");

	}
}
